<template>
	<view>
		<view>
			<swiper class="swiper" autoplay="ture" indicator-dots="ture" indicator-color="#333333">
				<swiper-item id="item1">
					<cover-image class="img" src="https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg">
					</cover-image>
				</swiper-item>
				<swiper-item id="item2">
					<cover-image class="img" src="https://ossweb-img.qq.com/images/lol/web201310/skin/big37006.jpg">
					</cover-image>
				</swiper-item>
				<swiper-item id="item3">
					<cover-image class="img" src="https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg">
					</cover-image>
				</swiper-item>
			</swiper>
		</view>
		<view>
			<uni-scroll-view data-v-137708e8="" class="bg-red nav text-center">
				<div class="uni-scroll-view">
					<div class="uni-scroll-view" style="overflow: auto hidden;">
						<div class="uni-scroll-view-content">
							<!---->
							<uni-view data-v-137708e8="" data-id="1" class="cu-item">销量：200</uni-view>
							<uni-view data-v-137708e8="" data-id="2" class="cu-item">收藏量：100</uni-view>
							<uni-view data-v-137708e8="" data-id="2" class="cu-item">点赞量：500</uni-view>
						</div>
					</div>
				</div>
			</uni-scroll-view>
		</view>
		<view>
			<uni-view data-v-5f580ccb="" class="basis-xs bg-grey margin-xs padding-sm radius">价格￥：500</uni-view>
		</view>
		<view>
			这里用来展示商品其他详情
		</view>
		
		<view>
			<uni-view data-v-cf183850="" class="cu-bar bg-white">
				<uni-view data-v-cf183850="" class="action">
					<uni-text data-v-cf183850="" class="cuIcon-titles text-green"><span></span></uni-text>
					<uni-text data-v-cf183850="" class="text-xl text-bold" @click='evaluate'><span>评价</span></uni-text>
				</uni-view>
			</uni-view>
		</view>
		<view style="width: 600rpx;height: 100rpx;background-color:#00CE47;">这里用来放该商品的所有评论</view>
		<view class="goodsDetials_bottom">
			<uni-view data-v-5f580ccb="" class="flex solid-bottom padding justify-center">
				<uni-view data-v-5f580ccb="" class="bg-grey padding-sm margin-xs radius" style="font-size: small;" @click="goHome">首页</uni-view>
				<uni-view data-v-5f580ccb="" class="bg-grey padding-sm margin-xs radius" @click="addCollect">收藏</uni-view>
				<uni-view data-v-5f580ccb="" class="bg-grey padding-sm margin-xs radius" @click="goConsult">咨询</uni-view>
				<uni-view data-v-5f580ccb="" class="bg-grey padding-sm margin-xs radius" style="background-color:#F55C23;" @click="addGoods">加入购物车</uni-view>
				<uni-view data-v-5f580ccb="" class="bg-grey padding-sm margin-xs radius" style="background-color:#F55C23;" @click="payImmediate">立即购买</uni-view>
			</uni-view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad:function(option){
			console.log("传过来了一个商品Id:"+option.goodsId);
				this.goodsId = option.goodsId;
			this.$req.getGoodsDetails(option.goodsId,0,3).then(res=>{
				if(res.code === 615){
					uni.navigateTo({
						url:'../login/login'
					})
				}else{
					// 从后端返回数据res中获取值
					this.goodsSpecs=res.data.goodsSpecs;
					uni.setStorageSync("goodsSpecs",res.data.goodsSpecs);
					
				}

				console.log(res);
			}),
			this.$req.isPurchase(option.goodsId,0,3).then(res=>{
				console.log("用户是否购买此商品："+res.data);
				this.isPurchase=res.data;
			}),
			this.$req.showEvaluate(option.goodsId,0,3).then(res=>{
				console.log("该商品所有评论："+res);
				this.allEvaluate=res.data;
			})
		},
		data() {
			return {
				details:'',
				goodsId:'',
				isPurchase:'',
				allEvaluate:'',
				goodsSpecs:[]
				
			}
		},
		methods: {
			addGoods(){
				uni.navigateTo({
					url:'./addGoods/addGoods'
				})
			},
			addCollect(){
				this.$req.addGoodsCollect(this.goodsId).then(res=>{
					console.log(res) 
				})
			},
			goHome(){
				uni.navigateBack({
					delta:1
				})
			},
			goConsult(){
				uni.showToast({
					title:"功能正在制作中，请期待"
				})
			},
			payImmediate(){
				uni.navigateTo({
					url:'./ordercommit/orderCommit'
				})
			},
			evaluate(){
				if(this.isPurchase){
					//用户曾购买此商品，可评论
					uni.showToast({
						title:"你可评论，但评论还在完善...."
					})
				}else{
					uni.showToast({
						title:"你没购买此商品，没资格评论"
					})
				}
			}
		}
	}
</script>

<style>
	.goodsDetials_bottom {
		position: absolute;
		bottom: 0;
	}
</style>
